<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="title">
  <h1>Gateways</h1>
</div>

<gio-table-wrapper [disableSearchInput]="true" [length]="nbTotalInstances" [filters]="filters" (filtersChange)="onFiltersChanged($event)">
  <table mat-table [dataSource]="filteredTableData" id="instancesTable" aria-label="Gateways table">
    <!-- Display name Column -->
    <ng-container matColumnDef="hostname">
      <th mat-header-cell *matHeaderCellDef id="hostname">Name</th>
      <td mat-cell *matCellDef="let element">
        <a [routerLink]="['.', element.id]" title="{{ element.hostname }}" data-testid="instance-list-row-instance-details-link">{{
          element.hostname
        }}</a>
      </td>
    </ng-container>

    <!-- Display version Column -->
    <ng-container matColumnDef="version">
      <th mat-header-cell *matHeaderCellDef id="version">Version</th>
      <td mat-cell *matCellDef="let element">
        {{ element.version }}
      </td>
    </ng-container>

    <!-- Display State Column -->
    <ng-container matColumnDef="state">
      <th mat-header-cell *matHeaderCellDef id="state">Status</th>
      <td mat-cell *matCellDef="let element">
        <mat-icon
          *ngIf="element.state === 'STARTED'"
          matTooltip="Started"
          class="state__instance-started"
          size="20"
          svgIcon="gio:play-circle"
        ></mat-icon>
        <mat-icon
          *ngIf="element.state === 'STOPPED'"
          matTooltip="Stopped"
          class="state__instance-stopped"
          size="20"
          svgIcon="gio:stop-circle"
        ></mat-icon>
        <mat-icon
          *ngIf="element.state === 'UNKNOWN'"
          matTooltip="Unknown"
          class="state__instance-unknown"
          size="20"
          svgIcon="gio:question-mark-circle"
        ></mat-icon>
      </td>
    </ng-container>

    <!-- Display Last Heartbeat Column -->
    <ng-container matColumnDef="lastHeartbeat">
      <th mat-header-cell *matHeaderCellDef id="lastHeartbeat">Last Heartbeat</th>
      <td mat-cell *matCellDef="let element">
        {{ element.lastHeartbeat | date: 'medium' }}
      </td>
    </ng-container>

    <!-- Display IP and port Column -->
    <ng-container matColumnDef="ip-port">
      <th mat-header-cell *matHeaderCellDef id="ip-port">IP and Port</th>
      <td mat-cell *matCellDef="let element">{{ element.ip }}:{{ element.port }}</td>
    </ng-container>

    <!-- Display OS Column -->
    <ng-container matColumnDef="os">
      <th mat-header-cell *matHeaderCellDef id="os">OS</th>
      <td mat-cell *matCellDef="let element">
        {{ element.os }}
      </td>
    </ng-container>

    <!-- Display Tenant Column -->
    <ng-container matColumnDef="tenant">
      <th mat-header-cell *matHeaderCellDef id="tenant">Tenant</th>
      <td mat-cell *matCellDef="let element">
        {{ element.tenant }}
      </td>
    </ng-container>

    <!-- Display Tags Column -->
    <ng-container matColumnDef="tags">
      <th mat-header-cell *matHeaderCellDef id="tags">Sharding Tags</th>
      <td mat-cell *matCellDef="let element">
        {{ element.tags }}
      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="this.displayedColumns" data-testid="instance-list-table-header"></tr>
    <tr mat-row *matRowDef="let row; columns: this.displayedColumns" data-testid="instance-list-table-row"></tr>

    <!-- Row shown when there is no data -->
    <tr class="mat-mdc-row mdc-data-table__row" *matNoDataRow>
      <td class="mat-mdc-cell mdc-data-table__cell" [attr.colspan]="this.displayedColumns.length">
        {{ 'There are no Gateway instances (yet).' }}
      </td>
    </tr>
  </table>
</gio-table-wrapper>
